<?php
namespace Kxdr\Model;
use Think\Model\ViewModel;
class GiftViewModel extends ViewModel {
	public $eid;
	public $sid;
	public $gift_quant;
	public $gift_names;
	public $gift_ids;
	public $viewFields = array(
		'event_gift'=>array('_table'=>"sm_kxdr_event_gifts",'id', 'event_id', 'event_player_id', 'think_type', 'think_type_way', 'gift_id','quantity'=>'event_quant', 'quantity_install', 'score_diff', 'get_type', 'add_time', 'getting_json', 'probability', 'type', 'level', 'level_name', 'lottery_times', 'name', 'promoid', 'tagid', 'pic_url', 'advance', 'every_minute', 'range_time_start', 'range_time_end', 'every_lotts', 'advance_quantity', 'ext_rule', 'medal_id', 'medal_name', 'medal_pic', 'rule_medal_id', 'rule_medal_name', 'rule_medal_pic', 'medal_quant', 'collect_items', 'order_items', 'cart_items', 'show_title', 'show_content', 'jifen', 'payment', 'pay_time_start', 'pay_time_end','_type'=>'LEFT'),
		'gift'=>array('_table'=>'sm_gifts','sid','status','type','name','price','quantity','pic_url','promoid','tag_id','_on'=>'event_gift.gift_id=gift.id','_type'=>'LEFT'),
		'e_player'=>array('_table'=>"sm_kxdr_event_players",'id'=>'epid','event_id','player_id','player_descrip'=>'event_player_descrip','title','think_type','think_type_way','_on'=>'e_player.id=event_gift.event_player_id','_type'=>'LEFT'),
		'player'=>array('_table'=>'sm_kxdr_players','chinese_name'=>'player_name','description'=>'player_descrip','is_team','team_id','_on'=>'e_player.player_id=player.id','_type'=>'LEFT'),
	);
	public function getEventGifts(){
		$gifts = $this->where("`event_gift`.`event_id`=".$this->eid." AND `event_gift`.`sid`=".$this->sid)->getField("id,player_id,event_quant,think_type,think_type_way,player_name,event_player_descrip,score_diff,get_type,add_time,name,price,pic_url,gift_id,title,probability,type,level,level_name,lottery_times,name,promoid,tagid,pic_url,advance,every_minute,range_time_start,range_time_end,every_lotts,advance_quantity,ext_rule,medal_id,medal_name,medal_pic,rule_medal_id,rule_medal_name,rule_medal_pic,medal_quant,collect_items,order_items,cart_items,show_title,show_content,jifen,payment,pay_time_start,pay_time_end");
		foreach($gifts as $gk=>$gft){
			if($gft["player_id"]==0){
				$gifts[$gk]["player_name"]="全部队伍";
			}
			switch($gft["score_diff"]){
				case -1:
				$gifts[$gk]["cffs"]="<b>没猜中</b>";
				break;
				case 0:
				$gifts[$gk]["cffs"]="完全猜中";
				break;
				default:
				$gifts[$gk]["cffs"]="差".$gft["score_diff"]."分猜中";
				break;
			}
			foreach(C("KXDR_GETWAY") as $gw){
				if($gw["id"]==$gft["get_type"] ){
					$gifts[$gk]["hqfs"] = $gw["name"];
					break;
				}
			}
			foreach(C("KXDR_THINK_WAY") as $gw){
				if($gw["id"]==$gft["think_type_way"] ){
					$gifts[$gk]["think_type_way_name"] = $gw["name"];
					break;
				}
			}
			switch($gft["advance"]){
				case "order" :
				$gifts[$gk]["icon"] = "icon-shopping-cart";
				break;
				case "lottery" :
				$gifts[$gk]["icon"] = "icon-star-empty";
				break;
				default:
				$gifts[$gk]["icon"] = "icon-ok";
				break;
			}
			$this->gifts = $gifts;
			$this->gift_quant = count($gifts);
			$this->gift_names[$gft["gift_id"]]["name"]=$gft["name"];
			$this->gift_names[$gft["gift_id"]]["pic_url"]=$gft["pic_url"];
			$this->gift_ids[$gft["gift_id"]]=$gft["gift_id"];
		}
	}
}
 